﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using JsonTest1.Net;
using JsonTest1.Configure;
using System.IO;
using JsonTest1.Data;
using JsonTest1.Xml;

namespace JsonTest1.NetEngine
{
    public class Top100Engine : HttpMessage
    {
         public Top100Engine()
        {
            base.init();
        }

        public void Request()
        {
            //this.OnDataStreamGenerated += new Net.HttpDataStreamCalback(HttpDataStreamCalback);
            String url = "http://www.jamendo.com/en/rss/top-track-weekc";
            BeginRequest(url);
        }



        public override  bool HttpGeneratorDataCallback(Stream stream){

            try
            {
                //解析xml,过滤错误
                string xmlStr = new StreamReader(stream).ReadToEnd();
                if (xmlStr == null)
                {
                    //AlbumFunctions.getAlbums();
                    HttpFailCalback(1, 1, new ResultData(1, 1, ""));
                }
                else
                {
                    if (httpStateListener != null)
                        httpStateListener.HttpDataStreamCalback(stream, new ResultData(0, 0, RSSFunctions.getTracksIdFromRss(xmlStr)));
                }
            }
          /*  catch (JsonException e)
            {
                HttpFailCalback(1, 1, new ResultData(1, 1, ""));
            }*/
            catch (Exception e)
            {

            }

            return true;
        }
 
    }
    
}
